<?php

namespace App\Jobs;

use App\Models\ImQueueErrorLogs;
use App\Services\Huanxin\UserServices;
use App\Services\RongCloud\UserService as RongUserService;
use App\Services\Netease\UserServices as NeteaseUserService;
use App\Services\Aliyun\Video\VideoServices;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class FriendTask implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $data = null;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data = null)
    {
        //
        $this->data = $data;
    }

    /**
     * @desc 加好友自动审核三个平台
     * @return bool
     * @author zhouzhou
     * @time 2021/12/24 16:30
     */
    public function handle()
    {
        // redis的数据
        $data = $this->data;
        if (!empty($data))
        {
            try
            {
                $userId = $data['user_id'];
                $otherUid = $data['other_uid'];

                $userServices= new UserServices();
                $userServices->addFriend($userId, $otherUid);

                $userNeteaseServices= new NeteaseUserService();
                $userNeteaseServices->addFriend($userId, $otherUid,3 );
            }catch (\Exception $e)
            {
                $imQueueErrorLogs = new ImQueueErrorLogs();
                $imQueueErrorLogs->insertQueueError(json_encode(['data'=>$data]), 4, $e->getMessage());
            }
        }
    }
}
